﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SimpleRest.Core;
using SimpleRest.Core.Extensions.OAuth;
using SimpleRest.Core.Extensions.OAuth.Exceptions;

namespace SimpleRest.WebTest.Services
{
    [Service("oauth2/tokens")]
    public class AccessTokensService : AccessTokenServiceBase<SpecialAccesstoken>
    {
        internal static Dictionary<SpecialAccesstoken, DateTime> AccessTokens = new Dictionary<SpecialAccesstoken, DateTime>();

        public override SpecialAccesstoken CreateAccessToken(Credentials credentials)
        {
            if (credentials.Username == "jerrod" && credentials.Password == "jerrod1")
            {
                DateTime expire = DateTime.Now.AddSeconds(60);

                var token = new SpecialAccesstoken()
                {
                    expires_in = 60,
                    refresh_token = null,
                    scope = "something",
                    OtherValuesIWant = "something else here",
                    token_type = "bearer",
                    access_token = Guid.NewGuid().ToString()
                };

                AccessTokens.Add(token, expire);

                return token;
            }

            throw new UnAuthorizedException();
        }
        public override SpecialAccesstoken CreateAccessToken(string authorizationCode, string redirectUri, string clientId)
        {
            return base.CreateAccessToken(authorizationCode, redirectUri, clientId);
        }
    }

    public class SpecialAccesstoken : AccessToken
    {
        public string OtherValuesIWant { get; set; }
    }
}